package heima3_2.cn.osc.ui.main_fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.oschina.app.R;

import java.util.ArrayList;
import java.util.List;

import heima3_2.cn.osc.base.BaseFragment;
import heima3_2.cn.osc.constant.ResultState;
import heima3_2.cn.osc.ui.adapter.TabAdapter;

/**
 * Created by ThinkPad on 2016/10/30.
 */

public class SyntherMainFragment extends BaseFragment {
    private String mParam1;
    public static final String[] tabTitle = new String[]{"资讯","热点","博客","推荐"};
    private TabLayout tab;
    private ViewPager viewpager;
    private TabAdapter adapter;
    private View mView;


    public SyntherMainFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString("key");
        }
    }


    @Override
    protected ResultState onLoadSubData() {
        return ResultState.LOAD_SUCCESS;
    }

    @Override
    protected View onCreateSubSuccessView(LayoutInflater inflater, ViewGroup container) {
        mView =inflater.inflate(R.layout.activity_synthe_size,container,false);
        iniView();
        iniData();
        return mView;
    }


    //TODO:抽取
    private void iniView() {
        tab = (TabLayout) mView.findViewById(R.id.tbl_synthe);
        viewpager = (ViewPager) mView.findViewById(R.id.vp_synthe);

    }
    //TODO:抽取
    private void iniData() {
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < tabTitle.length; i++) {
            fragments.add(SyntheFragment.newInstance(i + 1));
        }
        adapter = new TabAdapter(getFragmentManager(),fragments,tabTitle);
        viewpager.setAdapter(adapter);
        tab.setupWithViewPager(viewpager);
        tab.setTabMode(TabLayout.MODE_SCROLLABLE);
        tab.setTabGravity(TabLayout.GRAVITY_FILL);
        tab.setTabMode(TabLayout.MODE_FIXED);
    }
}
